package com.goods.business.controller;

import com.github.pagehelper.Page;
import com.goods.business.service.ProductCategoryService;
import com.goods.common.model.business.ProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liangliang
 * @Date 2021/11/8 16:05 Administrator
 * @Description
 */
@RestController
@RequestMapping("/business/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 获取物资类别的分类数据
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/categoryTree")
    public ResponseBean categoryTree(@RequestParam(required = false,value = "pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(required = false,value = "pageSize",defaultValue = "5") Integer pageSize){
      PageVO<ProductCategoryTreeNodeVO> productCategoryTreeNodeVOPageVO =productCategoryService.categoryTree(pageNum,pageSize);
        return ResponseBean.success(productCategoryTreeNodeVOPageVO);
    }

    /**
     * 获取父级的分类信息
     * @return
     */
    @GetMapping("/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){
        List<ProductCategoryTreeNodeVO> getParentCategoryTree=productCategoryService.getParentCategoryTree();

       return  ResponseBean.success(getParentCategoryTree) ;
    }

    /**
     * 添加物资类别的分类信息
     * @param productCategory
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductCategory productCategory){
        productCategoryService.add(productCategory);
        return ResponseBean.success();
    }

    /**
     * 根据ID查询物资类别的信息，用作数据回显
     * @param id
     * @return
     */
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductCategoryTreeNodeVO productCategoryTreeNodeVO=productCategoryService.edit(id);
        return ResponseBean.success(productCategoryTreeNodeVO);
    }

    /**
     * 修改物资类别信息
     * @param id
     * @param productCategoryVO
     * @return
     */
    @PutMapping("/update/{id}")
    public  ResponseBean update(@PathVariable Long id,@RequestBody ProductCategoryVO productCategoryVO){
        productCategoryService.update(id,productCategoryVO);
        return ResponseBean.success();
    }

    /**
     * 删除物资类信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        productCategoryService.delete(id);
        return ResponseBean.success();
    }
}
